package com.lyl.common.validation.validator;

import com.lyl.common.validation.annotation.FileNotEmpty;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author 罗亚龙
 * @date 2021/9/25 9:03
 */
public class FileNotEmptyConstraintValidatorWithMultipartFile implements ConstraintValidator<FileNotEmpty, MultipartFile> {
    String fieldName;

    @Override
    public void initialize(FileNotEmpty constraintAnnotation) {
        fieldName = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(MultipartFile file, ConstraintValidatorContext constraintValidatorContext) {
        return file != null && !file.isEmpty();
    }
}
